import { createSlice, PayloadAction } from '@reduxjs/toolkit';
export interface UserState {
  username: string;
  nickname: string;
}

const initialState: UserState = {
  username: '',
  nickname: '',
};

export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    loginReducer: (state: UserState, action: PayloadAction<UserState>) => {
      state.username = action.payload.username;
      state.nickname = action.payload.nickname;
    },
    logoutReducer: (state: UserState) => {
      state.username = '';
      state.nickname = '';
    },
  },
});

export const { loginReducer, logoutReducer } = userSlice.actions;
export default userSlice.reducer;
